package com.lihaozhe.handler;

import com.lihaozhe.constant.CommonConstant;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 李昊哲
 * @version 1.0
 * 2021/11/28 16:16
 */
@Configuration
public class LoginAuthenticationFailureHandler implements AuthenticationFailureHandler {
    private final CommonConstant commonConstant;

    public LoginAuthenticationFailureHandler(CommonConstant commonConstant) {
        this.commonConstant = commonConstant;
    }

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        response.sendRedirect(commonConstant.getSite());
    }
}
